(window.zowieJsonp=window.zowieJsonp||[]).push([[6],{52:function(e,n,t){"use strict";t.r(n),t.d(n,"getConversationId",function(){return _}),t.d(n,"saveConversationId",function(){return z}),t.d(n,"keepAlive",function(){return O}),t.d(n,"setup",function(){return T});var i=t(7),a=t(2),o=t(1),c="chatbot",r=void 0,s=!1,d=function(e){return"zowie-zendesk-conv-in-progress-"+e},u=function(e){return"true"===window.localStorage.getItem(e)},l=function(e,n){return window.localStorage.setItem(e,String(n))},v=t(17).a+"/api/v1/chat-integration-zendeskchat";var f=void 0,m=void 0,h=function(){var e=document.location.host.split("."),n=e.length,t="."+e.slice(n-2,n).join(".");document.cookie="__zlcmid=;path=/;domain="+t+";expires=Thu, 01 Jan 1970 00:00:01 GMT"},g=function(){return window.location.href.includes("glamira")||window.location.href.includes("sharkgaming.dk")||window.location.href.includes("sharkgaming.se")||window.location.href.includes("sharkgaming.no")||window.location.href.includes("cobbtuning.com")&&void 0!==window.require?new Promise(function(e,n){window.require(["https://dev.zopim.com/web-sdk/latest/web-sdk.js"],function(n){e(n)})}):new Promise(function(e,n){try{var t=document.createElement("script");t.type="text/javascript",t.async=!0,t.src="https://dev.zopim.com/web-sdk/latest/web-sdk.js",t.addEventListener("load",function(n){e(window.zChat)}),t.addEventListener("error",function(e){n("Failed to load Zendesk Chat script: "+JSON.stringify(e))}),document.body.appendChild(t)}catch(e){n("Failed to add Zendesk Chat script: "+JSON.stringify(e))}})};function p(e,n){for(var t=e.split(","),i=t[0].match(/:(.*?);/)[1],a=atob(t[1]),o=a.length,c=new Uint8Array(o);o--;)c[o]=a.charCodeAt(o);return new File([c],n,{type:i})}function b(e,n,t,i){var o=v+"/instances/"+n+"/conversations/"+e+"/messages/announcement";Object(a.c)(o,{text:t,visibility:i})}function k(e,n){var t=v+"/instances/"+n+"/conversations/"+e+"/agent-not-available";return Object(a.c)(t,{})}function y(e,n,t){"chatbot"!==c&&setTimeout(function(){return I(e,n,t,!1,[])},1e3)}function I(e,n,t,i,o){if("chatbot"!==c){var r=v+"/instances/"+t+"/conversations/"+n+"/messages";Object(a.a)(r).then(function(c){var r=c.data;if(i){var s=r.map(function(n){if(void 0!==n.text){var t=new Date(n.time),i=t.getHours(),a="0"+t.getMinutes(),o="0"+t.getSeconds(),c=i+":"+a.substr(-2)+":"+o.substr(-2);return n.author+" ("+c+"): "+n.text}return void 0!==n.fileData&&void 0!==n.fileName?void e.sendFile(p(n.fileData,n.fileName)):void 0}).join("\n\n"),d=o.map(function(e){return"tier"===e.key||"Tier"===e.key?"30-day GMV: $"+e.value:e.key+": "+e.value}).join("\n"),u=s;""!==u&&d.length>0&&"ac6b077fad4543ee898035e7eaf905eb"===t&&(u+="\n\n\nProperties:\n",u+=d),""!==u&&e.sendChatMsg(u)}else r.forEach(function(n){void 0!==n.text?e.sendChatMsg(n.text):void 0!==n.fileData&&void 0!==n.fileName&&e.sendFile(p(n.fileData,n.fileName))});if(r.length>0)return function(e,n,t){var i=v+"/instances/"+n+"/conversations/"+e+"/messages/seen";return Object(a.c)(i,{time:t})}(n,t,r[r.length-1].time).finally(function(){y(e,n,t)});y(e,n,t)})}}function w(e,n,t,a){if(["f4b3c2093a744fdc9eaaf0c00f4d7d3b","7a761b8ef2ea41369f7c8fe9bee9996e","1d1f478a1fd74e0393d44f9bb7c51b2f"].includes(n)){Object(o.g)("Checking department status: ",t,a);var r=u(d(e));if(void 0!==a)"offline"!==a.status||r||(k(e,n).finally(function(){c="chatbot"}),clearInterval(f),i.a.logger.info("livechat-zendesk-event-chat_departmentoffline",{instanceId:n,conversationId:e}));else void 0!==t.find(function(e){return"offline"!==e.status})||r||(k(e,n).finally(function(){c="chatbot"}),clearInterval(f),i.a.logger.info("livechat-zendesk-event-chat_departmentoffline",{instanceId:n,conversationId:e}))}}function j(e,n,t){(function(e,n){var t=v+"/instances/"+n+"/conversations/"+e+"/state";return Object(a.a)(t).then(function(e){return e.data}).catch(function(){return{owner:"chatbot",metadata:void 0}})})(n,t).then(function(i){var s=i.owner,d=i.metadata;if("zendesk"===s&&"chatbot"===c){c="zendesk";var u=e.getAllDepartments();if(Object(o.g)("Available departments: ",u),d){var l=u.find(function(e){return e.name===d});l?(e.setVisitorDefaultDepartment(l.id),w(n,t,u,l)):w(n,t,u)}else w(n,t,u);(function(e,n){var t=v+"/instances/"+n+"/conversations/"+e+"/metadata";return Object(a.a)(t).then(function(e){return e.data}).catch(function(){return{}})})(n,t).then(function(i){var a={};void 0!==i.name&&(a.display_name=i.name),void 0!==i.email&&(a.email=i.email),void 0!==i.phoneNumber&&(a.phone=i.phoneNumber),e.setVisitorInfo(a),I(e,n,t,!0,i.customProperties)}).catch(function(){I(e,n,t,!0,[])}).finally(function(){r=setTimeout(function(){return j(e,n,t)},500)})}else"chatbot"===s&&"zendesk"===c?(c="chatbot",r=setTimeout(function(){return j(e,n,t)},500)):r=setTimeout(function(){return j(e,n,t)},500)})}function _(e){return localStorage.getItem("zowie-zendesk-"+e+"-conversationId")}function z(e,n){localStorage.setItem("zowie-zendesk-"+e+"-conversationId",n)}function O(e){var n=e.accountKey,t=e.conversationId,a=e.instanceId;g().then(function(e){i.a.logger.info("livechat-zendesk-keepalive-load-success",{instanceId:a,conversationId:t,accountKey:n}),e.init({account_key:n})}).catch(function(e){Object(o.f)(e),i.a.logger.error("livechat-zendesk-keepalive-load-failed",{instanceId:a,conversationId:t,accountKey:n,errorRoot:e})})}function T(e,n){var t=e.accountKey,u=e.conversationId,p=e.instanceId;void 0!==r&&clearTimeout(r),s=!1,c="chatbot",_(p)!==u&&(h(),z(p,u)),g().then(function(e){Object(o.g)("Zowie - Zendesk - SDK loaded"),i.a.logger.info("livechat-zendesk-load-success",{instanceId:p,conversationId:u,accountKey:t}),e.on("connection_update",function(n){Object(o.g)("Zowie - Zendesk - connection_update",n),i.a.logger.info("livechat-zendesk-event-connection_update",{instanceId:p,conversationId:u,accountKey:t,status:n}),"connected"===n&&!1===s&&(s=!0,r=setTimeout(function(){return j(e,u,p)},1e3))}),e.on("chat",function(e){"chat.msg"===e.type&&e.msg&&"visitor"!==e.nick&&s?(Object(o.g)("Zowie - Zendesk - chat_message",e),function(e,n,t,i,o){var c=t?t.replace("agent:",""):void 0,r=v+"/instances/"+n+"/conversations/"+e+"/messages/text";Object(a.c)(r,{text:i,userId:c,time:o})}(u,p,e.nick,e.msg,e.timestamp)):"chat.file"===e.type&&"visitor"!==e.nick&&e.attachment&&s?(Object(o.g)("Zowie - Zendesk - chat_visitor",e),function(e,n,t,i,o){var c=t?t.replace("agent:",""):void 0,r=v+"/instances/"+n+"/conversations/"+e+"/messages/file";Object(a.c)(r,{url:i,mime:o,userId:c})}(u,p,e.nick,e.attachment.url,e.attachment.mime_type)):"chat.queue_position"===e.type&&e.queue_position&&s?e.queue_position>0&&(b(u,p,"Current queue position: "+e.queue_position,"TEMPORARY"),clearInterval(f),void 0!==e.queue_position&&(m=e.queue_position,f=setInterval(function(){b(u,p,"Current queue position: "+m,"TEMPORARY")},3e4))):"chat.memberjoin"===e.type&&"visitor"!==e.nick&&e.display_name&&s?(Object(o.g)("Zowie - Zendesk - chat_memberjoin",e),b(u,p,e.display_name+" joined.","PERSISTENT"),function(e,n){var t=v+"/instances/"+n+"/conversations/"+e+"/agent-joined";Object(a.c)(t,{})}(u,p),l(d(u),!0),clearInterval(f),i.a.logger.info("livechat-zendesk-event-chat_memberjoin",{instanceId:p,conversationId:u,accountKey:t,event:e})):"chat.memberleave"===e.type&&"visitor"!==e.nick&&e.display_name&&s?(Object(o.g)("Zowie - Zendesk - chat_memberleave",e),b(u,p,e.display_name+" left.","PERSISTENT"),l(d(u),!1),clearInterval(f),i.a.logger.info("livechat-zendesk-event-chat_memberleave",{instanceId:p,conversationId:u,accountKey:t,event:e})):"typing"===e.type&&!0===e.typing&&"visitor"!==e.nick&&s?function(e,n){var t=v+"/instances/"+n+"/conversations/"+e+"/messages/typing";Object(a.c)(t,{})}(u,p):"chat.memberleave"===e.type&&"visitor"===e.nick&&s&&(function(e,n){var t=v+"/instances/"+n+"/conversations/"+e+"/end-chat";return Object(a.c)(t,{})}(u,p).finally(function(){c="chatbot",l(d(u),!1)}),clearInterval(f),i.a.logger.info("livechat-zendesk-event-chat_memberleave",{instanceId:p,conversationId:u,accountKey:t,event:e}))}),e.on("agent_update",function(e){e.nick&&function(e,n,t,i,o){var c=t?t.replace("agent:",""):void 0,r=v+"/instances/"+n+"/conversations/"+e+"/messages/user-metadata";Object(a.c)(r,{name:i,imageUrl:o,userId:c})}(u,p,e.nick,e.display_name,e.avatar_path)}),e.on("error",function(e){i.a.logger.error("livechat-zendesk-event-error",{instanceId:p,conversationId:u,accountKey:t,event:e})}),e.init({account_key:t})}).catch(function(e){Object(o.f)(e),i.a.logger.error("livechat-zendesk-load-failed",{instanceId:p,conversationId:u,accountKey:t,errorRoot:e,errorRetry:n}),(void 0===n||n<10)&&setTimeout(function(){T({accountKey:t,conversationId:u,instanceId:p},n?n+1:1)},250)})}}}]);